﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;

namespace BtLabelBLL
{
    public class MultimeterBLL
    {
        [DllImport("VisaTestDll.dll", EntryPoint = "measure_current")]
        static extern void measure_current(string address, ref double value, ref bool success);
        /// <summary>
        /// 万用表地址 
        /// "TCPIP0::169.254.4.61";  //Example for LAN
        /// </summary>
        public string _addr;
        /// <summary>
        /// 通道日志控件
        /// </summary>
        public RichTextBox _richTextBoxInfo;
        /// <summary>
        /// 读取电流值
        /// </summary>
        /// <param name="delay"></param>
        /// <returns></returns>
        public bool GetCurrent(ref double current, int delay = 2000)
        {
            try
            {
                //UiBLL.RichTextBoxAppendText(_richTextBoxInfo, Brushes.SteelBlue, DateTime.Now.ToString("HH:mm:ss.fff") + "\r\n");
                //UiBLL.RichTextBoxAppendText(_richTextBoxInfo, Brushes.SteelBlue, "等待" + delay/1000 + "秒");
                //Thread.Sleep(delay);
                //读取电流值
                bool isOk = false;
                measure_current(_addr, ref current, ref isOk);
                if (isOk==false)
                {
                   return false;
                }
                //UiBLL.RichTextBoxAppendText(_richTextBoxInfo, Brushes.SteelBlue, DateTime.Now.ToString("HH:mm:ss.fff") + "\r\nRecieve:" + current);
                return true;
            }
            catch (Exception ex)
            {
                //return false;
                throw ex;
            }

        }
    }
}
